﻿using System;
using System.ComponentModel;

namespace HalconDotNet
{
	/// <summary>Represents an instance of a lexicon.</summary>
	// Token: 0x02000046 RID: 70
	public class HLexicon : HHandle
	{
		// Token: 0x06000972 RID: 2418 RVA: 0x0000883B File Offset: 0x00006A3B
		[EditorBrowsable(EditorBrowsableState.Never)]
		public HLexicon() : base(HHandleBase.UNDEF)
		{
		}

		// Token: 0x06000973 RID: 2419 RVA: 0x0003D3DC File Offset: 0x0003B5DC
		[EditorBrowsable(EditorBrowsableState.Never)]
		public HLexicon(IntPtr handle) : base(handle)
		{
			this.AssertSemType();
		}

		// Token: 0x06000974 RID: 2420 RVA: 0x0003D3EB File Offset: 0x0003B5EB
		[EditorBrowsable(EditorBrowsableState.Never)]
		public HLexicon(HHandle handle) : base(handle)
		{
			this.AssertSemType();
		}

		// Token: 0x06000975 RID: 2421 RVA: 0x0003D3FA File Offset: 0x0003B5FA
		private void AssertSemType()
		{
			base.AssertSemType("lexicon");
		}

		// Token: 0x06000976 RID: 2422 RVA: 0x0003D407 File Offset: 0x0003B607
		internal static int LoadNew(IntPtr proc, int parIndex, int err, out HLexicon obj)
		{
			obj = new HLexicon(HHandleBase.UNDEF);
			return obj.Load(proc, parIndex, err);
		}

		// Token: 0x06000977 RID: 2423 RVA: 0x0003D420 File Offset: 0x0003B620
		internal static int LoadNew(IntPtr proc, int parIndex, int err, out HLexicon[] obj)
		{
			HTuple htuple;
			err = HTuple.LoadNew(proc, parIndex, err, out htuple);
			obj = new HLexicon[htuple.Length];
			for (int i = 0; i < htuple.Length; i++)
			{
				obj[i] = new HLexicon(HalconAPI.IsLegacyHandleMode() ? htuple[i].IP : htuple[i].H);
			}
			htuple.Dispose();
			return err;
		}

		/// <summary>
		///   Create a lexicon from a text file.
		///   Modified instance represents: Handle of the lexicon.
		/// </summary>
		/// <param name="name">Unique name for the new lexicon. Default: "lex1"</param>
		/// <param name="fileName">Name of a text file containing words for the new lexicon. Default: "words.txt"</param>
		// Token: 0x06000978 RID: 2424 RVA: 0x0003D490 File Offset: 0x0003B690
		public HLexicon(string name, string fileName)
		{
			IntPtr proc = HalconAPI.PreCall(670);
			HalconAPI.StoreS(proc, 0, name);
			HalconAPI.StoreS(proc, 1, fileName);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			num = base.Load(proc, 0, num);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Create a lexicon from a tuple of words.
		///   Modified instance represents: Handle of the lexicon.
		/// </summary>
		/// <param name="name">Unique name for the new lexicon. Default: "lex1"</param>
		/// <param name="words">Word list for the new lexicon. Default: ["word1","word2","word3"]</param>
		// Token: 0x06000979 RID: 2425 RVA: 0x0003D4E4 File Offset: 0x0003B6E4
		public HLexicon(string name, HTuple words)
		{
			IntPtr proc = HalconAPI.PreCall(671);
			HalconAPI.StoreS(proc, 0, name);
			HalconAPI.Store(proc, 1, words);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(words);
			num = base.Load(proc, 0, num);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Clear a lexicon.
		///   Instance represents: Handle of the lexicon.
		/// </summary>
		// Token: 0x0600097A RID: 2426 RVA: 0x0003D540 File Offset: 0x0003B740
		public void ClearLexicon()
		{
			IntPtr proc = HalconAPI.PreCall(666);
			base.Store(proc, 0);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Find a similar word in a lexicon.
		///   Instance represents: Handle of the lexicon.
		/// </summary>
		/// <param name="word">Word to be looked up. Default: "word"</param>
		/// <param name="numCorrections">Difference between the words in edit operations.</param>
		/// <returns>Most similar word found in the lexicon.</returns>
		// Token: 0x0600097B RID: 2427 RVA: 0x0003D574 File Offset: 0x0003B774
		public string SuggestLexicon(string word, out int numCorrections)
		{
			IntPtr proc = HalconAPI.PreCall(667);
			base.Store(proc, 0);
			HalconAPI.StoreS(proc, 1, word);
			HalconAPI.InitOCT(proc, 0);
			HalconAPI.InitOCT(proc, 1);
			int num = HalconAPI.CallProcedure(proc);
			string result;
			num = HalconAPI.LoadS(proc, 0, num, out result);
			num = HalconAPI.LoadI(proc, 1, num, out numCorrections);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			return result;
		}

		/// <summary>
		///   Check if a word is contained in a lexicon.
		///   Instance represents: Handle of the lexicon.
		/// </summary>
		/// <param name="word">Word to be looked up. Default: "word"</param>
		/// <returns>Result of the search.</returns>
		// Token: 0x0600097C RID: 2428 RVA: 0x0003D5D8 File Offset: 0x0003B7D8
		public int LookupLexicon(string word)
		{
			IntPtr proc = HalconAPI.PreCall(668);
			base.Store(proc, 0);
			HalconAPI.StoreS(proc, 1, word);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			int result;
			num = HalconAPI.LoadI(proc, 0, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			return result;
		}

		/// <summary>
		///   Query all words from a lexicon.
		///   Instance represents: Handle of the lexicon.
		/// </summary>
		/// <returns>List of all words.</returns>
		// Token: 0x0600097D RID: 2429 RVA: 0x0003D628 File Offset: 0x0003B828
		public HTuple InspectLexicon()
		{
			IntPtr proc = HalconAPI.PreCall(669);
			base.Store(proc, 0);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HTuple result;
			num = HTuple.LoadNew(proc, 0, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			return result;
		}

		/// <summary>
		///   Create a lexicon from a text file.
		///   Modified instance represents: Handle of the lexicon.
		/// </summary>
		/// <param name="name">Unique name for the new lexicon. Default: "lex1"</param>
		/// <param name="fileName">Name of a text file containing words for the new lexicon. Default: "words.txt"</param>
		// Token: 0x0600097E RID: 2430 RVA: 0x0003D670 File Offset: 0x0003B870
		public void ImportLexicon(string name, string fileName)
		{
			this.Dispose();
			IntPtr proc = HalconAPI.PreCall(670);
			HalconAPI.StoreS(proc, 0, name);
			HalconAPI.StoreS(proc, 1, fileName);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			num = base.Load(proc, 0, num);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Create a lexicon from a tuple of words.
		///   Modified instance represents: Handle of the lexicon.
		/// </summary>
		/// <param name="name">Unique name for the new lexicon. Default: "lex1"</param>
		/// <param name="words">Word list for the new lexicon. Default: ["word1","word2","word3"]</param>
		// Token: 0x0600097F RID: 2431 RVA: 0x0003D6C4 File Offset: 0x0003B8C4
		public void CreateLexicon(string name, HTuple words)
		{
			this.Dispose();
			IntPtr proc = HalconAPI.PreCall(671);
			HalconAPI.StoreS(proc, 0, name);
			HalconAPI.Store(proc, 1, words);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(words);
			num = base.Load(proc, 0, num);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
		}
	}
}
